package com.wz.controller;

import com.wz.config.Normal;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.http.HttpService;

import java.io.IOException;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: demo
 * @description:
 * @author: Wangzheng
 * @create: 2020-12-21 17:23
 **/
@RestController
@RequestMapping("/test")
public class test {

	@RequestMapping("/test1")
	public BigInteger getBigBlockNumber() {
		Web3j web3j = Web3j.build(new HttpService(Normal.SERVER));
		EthBlockNumber send;
		try {
			send = web3j.ethBlockNumber().send();
			String result = send.getResult();

			BigInteger bigInteger = BigInteger.valueOf(Integer.parseInt(result.replaceAll("^0[x|X]", ""), 16));
			return bigInteger;
		} catch (IOException e) {
			System.out.println("异常信息" + " " + e);
		}
		return null;
	}


	@RequestMapping("/test2")
	public void method2() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int time = 1608635832;
		String time_Date = sdf.format(new Date(time * 1000L));
		System.out.println(time_Date);
	}

	@RequestMapping("/test3")
	public void method3() {
		Web3j web3j = Web3j.build(new HttpService(Normal.SERVER));


	
		
	}
}
	